package com.lvyou.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lvyou.entity.Goods;
import com.lvyou.mapper.IGoodsMapper;
import com.lvyou.util.TurnPage;
import com.lvyou.util.UUIDTools;

@Service("GoodsSrv")
public class GoodsSrv {

	@Resource
	private IGoodsMapper dao;
	
	public List<Goods> queryList(String name,Integer lowPrice,Integer highPrice,Integer status,TurnPage turnPage) throws Exception{
		if(name!=null && !"".equals(name)){
			name=name+"%";
		}
		return dao.queryList(name, lowPrice, highPrice,status, turnPage);
	}
	
	public PageInfo<Goods> mgrQueryList(String name,String startDate,String endtDate,Integer status,int pageNum,int pageSize) throws Exception{
		Page page=PageHelper.startPage(pageNum, pageSize, true);
		if(name!=null && !"".equals(name)){
			name=name+"%";
		}
		List list=dao.mgrQueryList(name, startDate, endtDate,status);
		
		PageInfo<Goods> pageInfo=new PageInfo<Goods>(list,page.getPages());
		
		return pageInfo;
	}
	
	public int add(Goods goods) throws Exception {
		goods.setId(UUIDTools.randomUUID());
		Date date=new Date();
		goods.setCreateTime(date);
		goods.setUpdateTime(date);
		return dao.add(goods);
	}
	public int updateById(Goods goods) throws Exception {
		Date date=new Date();
		goods.setUpdateTime(date);
		return dao.updateById(goods);
	}
	
	public int deleteByIds(String[] ids) throws Exception{
		return dao.deleteByIds(ids);
	}
	public Goods showGoodsById(String id)throws Exception{
		return dao.queryById(id);
	}
}
